 package server.maps.events;

 import client.MapleCharacter;
import client.MapleQuestStatus;
import client.MapleTraitType;
import handling.channel.ChannelServer;
import handling.world.WorldPartyService;
import handling.world.party.MaplePartyCharacter;
import handling.world.party.PartySearch;
import server.Timer;
import server.life.MapleLifeFactory;
import server.maps.MapleMap;
import server.quest.MapleQuest;
import tools.MaplePacketCreator;
import tools.Randomizer;

import java.util.concurrent.ScheduledFuture;
















 public class Event_PyramidSubway
 {
   private final int type;
/*  22 */   private int kill = 0;
/*  23 */   private int cool = 0;
/*  24 */   private int miss = 0;
/*  25 */   private int skill = 0;
/*  26 */   private int energybar = 100;
/*  27 */   private int bar = 0;
   private boolean broaded = false;
   private ScheduledFuture<?> energyBarDecrease;
   private ScheduledFuture<?> timerSchedule;

   public Event_PyramidSubway(MapleCharacter c) {
/*  33 */     int mapid = c.getMapId();
/*  34 */     if (mapid / 10000 == 91032) {
/*  35 */       this.type = -1;
     } else {
/*  37 */       this.type = mapid % 10000 / 1000;
     }
/*  39 */     if (c.getParty() == null || c.getParty().getLeader().getId() == c.getId()) {
/*  40 */       if (c.getParty() != null && c.getParty().getLeader().getId() == c.getId()) {
/*  41 */         PartySearch ps = WorldPartyService.getInstance().getSearch(c.getParty());
/*  42 */         if (ps != null) {
/*  43 */           WorldPartyService.getInstance().removeSearch(ps, "The Party Listing has been removed because the Party Quest started.");
         }
       }
/*  46 */       commenceTimerNextMap(c, 1);
/*  47 */       this.energyBarDecrease = Timer.MapTimer.getInstance().register(() -> {
/*  48 */             this.energybar -= (c.getParty() != null && c.getParty().getMembers().size() > 1) ? 5 : 2;
             if (this.broaded) {
               c.getMap().respawn(true);
             } else {
               this.broaded = true;
             }
             if (this.energybar <= 0) {
               fail(c);
             }
           },1000L);
     }
   }


   public static boolean warpStartSubway(MapleCharacter c) {
/*  63 */     int mapid = 910320100;

/*  65 */     ChannelServer ch = c.getClient().getChannelServer();
/*  66 */     for (int i = 0; i < 5; i++) {
/*  67 */       MapleMap map = ch.getMapFactory().getMap(910320100 + i);
/*  68 */       if (map.getCharactersSize() == 0) {
/*  69 */         clearMap(map, false);
/*  70 */         changeMap(c, map, 25, 30);
/*  71 */         return true;
       }
     }
/*  74 */     return false;
   }

   public static boolean warpBonusSubway(MapleCharacter c) {
/*  78 */     int mapid = 910320010;

/*  80 */     ChannelServer ch = c.getClient().getChannelServer();
/*  81 */     for (int i = 0; i < 20; i++) {
/*  82 */       MapleMap map = ch.getMapFactory().getMap(910320010 + i);
/*  83 */       if (map.getCharactersSize() == 0) {
/*  84 */         clearMap(map, false);
/*  85 */         c.changeMap(map, map.getPortal(0));
/*  86 */         return true;
       }
     }
/*  89 */     return false;
   }

   public static boolean warpNextMap_Subway(MapleCharacter c) {
/*  93 */     int currentmap = c.getMapId();
/*  94 */     int thisStage = (currentmap - 910320100) / 100;

/*  96 */     MapleMap map = c.getMap();
/*  97 */     clearMap(map, true);
/*  98 */     ChannelServer ch = c.getClient().getChannelServer();
/*  99 */     if (thisStage >= 2) {
/* 100 */       map = ch.getMapFactory().getMap(910330001);
/* 101 */       changeMap(c, map, 1, 200, 1);
/* 102 */       return true;
     }
/* 104 */     int nextmapid = 910320100 + (thisStage + 1) * 100;
/* 105 */     for (int i = 0; i < 5; i++) {
/* 106 */       map = ch.getMapFactory().getMap(nextmapid + i);
/* 107 */       if (map.getCharactersSize() == 0) {
/* 108 */         clearMap(map, false);
/* 109 */         changeMap(c, map, 1, 200, 1);
/* 110 */         return true;
       }
     }
/* 113 */     return false;
   }

   public static boolean warpStartPyramid(MapleCharacter c, int difficulty) {
/* 117 */     int mapid = 926010100 + difficulty * 1000;
/* 118 */     int minLevel = 40, maxLevel = 60;
/* 119 */     switch (difficulty) {
       case 1:
/* 121 */         minLevel = 45;
         break;
       case 2:
/* 124 */         minLevel = 50;
         break;
       case 3:
/* 127 */         minLevel = 61;
/* 128 */         maxLevel = 200;
         break;
     }
/* 131 */     ChannelServer ch = c.getClient().getChannelServer();
/* 132 */     for (int i = 0; i < 5; i++) {
/* 133 */       MapleMap map = ch.getMapFactory().getMap(mapid + i);
/* 134 */       if (map.getCharactersSize() == 0) {
/* 135 */         clearMap(map, false);
/* 136 */         changeMap(c, map, minLevel, maxLevel);
/* 137 */         return true;
       }
     }
/* 140 */     return false;
   }

   public static boolean warpBonusPyramid(MapleCharacter c, int difficulty) {
/* 144 */     int mapid = 926010010 + difficulty * 20;

/* 146 */     ChannelServer ch = c.getClient().getChannelServer();
/* 147 */     for (int i = 0; i < 20; i++) {
/* 148 */       MapleMap map = ch.getMapFactory().getMap(mapid + i);
/* 149 */       if (map.getCharactersSize() == 0) {
/* 150 */         clearMap(map, false);
/* 151 */         c.changeMap(map, map.getPortal(0));
/* 152 */         return true;
       }
     }
/* 155 */     return false;
   }

   public static boolean warpNextMap_Pyramid(MapleCharacter c, int difficulty) {
/* 159 */     int currentmap = c.getMapId();
/* 160 */     int thisStage = (currentmap - 926010100 + difficulty * 1000) / 100;

/* 162 */     MapleMap map = c.getMap();
/* 163 */     clearMap(map, true);
/* 164 */     ChannelServer ch = c.getClient().getChannelServer();
/* 165 */     if (thisStage >= 4) {
/* 166 */       map = ch.getMapFactory().getMap(926020001 + difficulty);
/* 167 */       changeMap(c, map, 1, 200, 1);
/* 168 */       return true;
     }
/* 170 */     int nextmapid = 926010100 + (thisStage + 1) * 100 + difficulty * 1000;
/* 171 */     for (int i = 0; i < 5; i++) {
/* 172 */       map = ch.getMapFactory().getMap(nextmapid + i);
/* 173 */       if (map.getCharactersSize() == 0) {
/* 174 */         clearMap(map, false);
/* 175 */         changeMap(c, map, 1, 200, 1);
/* 176 */         return true;
       }
     }
/* 179 */     return false;
   }

   private static void changeMap(MapleCharacter c, MapleMap map, int minLevel, int maxLevel) {
/* 183 */     changeMap(c, map, minLevel, maxLevel, 0);
   }

   private static void changeMap(MapleCharacter c, MapleMap map, int minLevel, int maxLevel, int clear) {
/* 187 */     MapleMap oldMap = c.getMap();
/* 188 */     if (c.getParty() != null && c.getParty().getMembers().size() > 1) {
/* 189 */       for (MaplePartyCharacter mpc : c.getParty().getMembers()) {
/* 190 */         MapleCharacter chr = oldMap.getCharacterById(mpc.getId());
/* 191 */         if (chr != null && chr.getId() != c.getId() && chr.getLevel() >= minLevel && chr.getLevel() <= maxLevel) {
/* 192 */           if (clear == 1) {
/* 193 */             chr.send(MaplePacketCreator.showEffect("killing/clear"));
/* 194 */           } else if (clear == 2) {
/* 195 */             chr.send(MaplePacketCreator.showEffect("killing/fail"));
           }
/* 197 */           chr.changeMap(map, map.getPortal(0));
         }
       }
     }
/* 201 */     if (clear == 1) {
/* 202 */       c.getClient().announce(MaplePacketCreator.showEffect("killing/clear"));
/* 203 */     } else if (clear == 2) {
/* 204 */       c.getClient().announce(MaplePacketCreator.showEffect("killing/fail"));
     }
/* 206 */     c.changeMap(map, map.getPortal(0));
   }

   private static void clearMap(MapleMap map, boolean check) {
/* 210 */     if (check && map.getCharactersSize() > 0) {
       return;
     }
/* 213 */     map.resetFully(false);
   }

   public final void fullUpdate(MapleCharacter c, int stage) {
/* 217 */     broadcastEnergy(c, "massacre_party", (c.getParty() == null) ? 0 : c.getParty().getMembers().size());
/* 218 */     broadcastEnergy(c, "massacre_miss", this.miss);
/* 219 */     broadcastEnergy(c, "massacre_cool", this.cool);
/* 220 */     broadcastEnergy(c, "massacre_skill", this.skill);
/* 221 */     broadcastEnergy(c, "massacre_laststage", stage - 1);
/* 222 */     broadcastEnergy(c, "massacre_hit", this.kill);
/* 223 */     broadcastUpdate(c);
   }

   public final void commenceTimerNextMap(MapleCharacter c, int stage) {
/* 227 */     if (this.timerSchedule != null) {
/* 228 */       this.timerSchedule.cancel(false);
/* 229 */       this.timerSchedule = null;
     }
/* 231 */     MapleMap ourMap = c.getMap();
/* 232 */     int time = ((this.type == -1) ? 180 : ((stage == 1) ? 240 : 300)) - 1;
/* 233 */     this.energybar = 100;
/* 234 */     this.bar = 0;
/* 235 */     if (c.getParty() != null && c.getParty().getMembers().size() > 1) {
/* 236 */       for (MaplePartyCharacter mpc : c.getParty().getMembers()) {
/* 237 */         MapleCharacter chr = ourMap.getCharacterById(mpc.getId());
/* 238 */         if (chr != null) {
/* 239 */           chr.send(MaplePacketCreator.getClock(time));
/* 240 */           chr.send(MaplePacketCreator.showEffect("killing/first/number/" + stage));
/* 241 */           chr.send(MaplePacketCreator.showEffect("killing/first/stage"));
/* 242 */           chr.send(MaplePacketCreator.showEffect("killing/first/start"));
/* 243 */           fullUpdate(chr, stage);
         }
       }
     } else {
/* 247 */       c.getClient().announce(MaplePacketCreator.getClock(time));
/* 248 */       c.getClient().announce(MaplePacketCreator.showEffect("killing/first/number/" + stage));
/* 249 */       c.getClient().announce(MaplePacketCreator.showEffect("killing/first/stage"));
/* 250 */       c.getClient().announce(MaplePacketCreator.showEffect("killing/first/start"));
/* 251 */       fullUpdate(c, stage);
     }
/* 253 */     if (this.type != -1 && (stage == 4 || stage == 5)) {
/* 254 */       for (int i = 0; i < ((stage == 4) ? 1 : 2); i++)
       {

/* 257 */         ourMap.spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(9700023), c.getPosition());
       }
     }
/* 260 */     this.timerSchedule = Timer.MapTimer.getInstance().schedule(() -> { boolean ret = false; if (this.type == -1) { ret = warpNextMap_Subway(c); } else { ret = warpNextMap_Pyramid(c, this.type); }  if (!ret) fail(c);  },time * 1000L);
   }











   public final void onKill(MapleCharacter c) {
/* 274 */     this.kill++;
/* 275 */     this.bar++;
/* 276 */     if (Randomizer.nextInt(100) < 5) {
/* 277 */       this.cool++;
/* 278 */       this.bar++;
/* 279 */       broadcastEnergy(c, "massacre_cool", this.cool);
     }
/* 281 */     this.energybar++;
/* 282 */     if (this.energybar > 100) {
/* 283 */       this.energybar = 100;
     }
/* 285 */     if (this.type != -1) {
/* 286 */       for (int i = 5; i >= 1; i--) {
/* 287 */         if ((this.kill + this.cool) % i * 100 == 0 && Randomizer.nextInt(100) < 20) {
/* 288 */           broadcastEffect(c, "killing/yeti" + (i - 1));

           break;
         }
       }
/* 293 */       if ((this.kill + this.cool) % 500 == 0) {
/* 294 */         this.skill++;
/* 295 */         broadcastEnergy(c, "massacre_skill", this.skill);
       }
     }

/* 299 */     broadcastUpdate(c);
/* 300 */     broadcastEnergy(c, "massacre_hit", this.kill);
   }

   public final void onMiss(MapleCharacter c) {
/* 304 */     this.miss++;
/* 305 */     this.energybar -= 5;
/* 306 */     broadcastUpdate(c);
/* 307 */     broadcastEnergy(c, "massacre_miss", this.miss);
   }

   public final boolean onSkillUse(MapleCharacter c) {
/* 311 */     if (this.skill > 0 && this.type != -1) {
/* 312 */       this.skill--;
/* 313 */       broadcastEnergy(c, "massacre_skill", this.skill);
/* 314 */       return true;
     }
/* 316 */     return false;
   }

   public final void onChangeMap(MapleCharacter c, int newmapid) {
/* 320 */     if ((newmapid == 910330001 && this.type == -1) || (newmapid == 926020001 + this.type && this.type != -1)) {
/* 321 */       succeed(c);
     }
/* 323 */     else if (this.type == -1 && (newmapid < 910320100 || newmapid > 910320304)) {
/* 324 */       dispose(c);
/* 325 */     } else if (this.type != -1 && (newmapid < 926010100 || newmapid > 926013504)) {
/* 326 */       dispose(c);
/* 327 */     } else if (c.getParty() == null || c.getParty().getLeader().getId() == c.getId()) {
/* 328 */       this.energybar = 100;
/* 329 */       commenceTimerNextMap(c, newmapid % 1000 / 100);
     }
   }


   public final void succeed(MapleCharacter c) {
/* 335 */     MapleQuestStatus record = c.getQuestNAdd(MapleQuest.getInstance((this.type == -1) ? 7662 : 7760));
/* 336 */     String data = record.getCustomData();
/* 337 */     if (data == null) {
/* 338 */       record.setCustomData("0");
/* 339 */       data = record.getCustomData();
     }
/* 341 */     int mons = Integer.parseInt(data);
/* 342 */     int tk = this.kill + this.cool;
/* 343 */     record.setCustomData(String.valueOf(mons + tk));
/* 344 */     byte rank = 4;
/* 345 */     if (this.type == -1) {
/* 346 */       if (tk >= 2000) {
/* 347 */         rank = 0;
/* 348 */       } else if (tk >= 1500 && tk <= 1999) {
/* 349 */         rank = 1;
/* 350 */       } else if (tk >= 1000 && tk <= 1499) {
/* 351 */         rank = 2;
/* 352 */       } else if (tk >= 500 && tk <= 999) {
/* 353 */         rank = 3;
       }

/* 356 */     } else if (tk >= 3000) {
/* 357 */       rank = 0;
/* 358 */     } else if (tk >= 2000 && tk <= 2999) {
/* 359 */       rank = 1;
/* 360 */     } else if (tk >= 1500 && tk <= 1999) {
/* 361 */       rank = 2;
/* 362 */     } else if (tk >= 500 && tk <= 1499) {
/* 363 */       rank = 3;
     }


/* 367 */     int pt = 0;
/* 368 */     switch (this.type) {
       case 0:
/* 370 */         switch (rank) {
           case 0:
/* 372 */             pt = 30500;
             break;
           case 1:
/* 375 */             pt = 25000;
             break;
           case 2:
/* 378 */             pt = 21750;
             break;
           case 3:
/* 381 */             pt = 12000;
             break;
         }
         break;
       case 1:
/* 386 */         switch (rank) {
           case 0:
/* 388 */             pt = 36000;
             break;
           case 1:
/* 391 */             pt = 30000;
             break;
           case 2:
/* 394 */             pt = 25750;
             break;
           case 3:
/* 397 */             pt = 13000;
             break;
         }
         break;
       case 2:
/* 402 */         switch (rank) {
           case 0:
/* 404 */             pt = 36500;
             break;
           case 1:
/* 407 */             pt = 35000;
             break;
           case 2:
/* 410 */             pt = 27250;
             break;
           case 3:
/* 413 */             pt = 14000;
             break;
         }
         break;
       case 3:
/* 418 */         switch (rank) {
           case 0:
/* 420 */             pt = 47000;
             break;
           case 1:
/* 423 */             pt = 40000;
             break;
           case 2:
/* 426 */             pt = 29500;
             break;
           case 3:
/* 429 */             pt = 18000;
             break;
         }
         break;
       default:
/* 434 */         switch (rank) {
           case 0:
/* 436 */             pt = 12000;
             break;
           case 1:
/* 439 */             pt = 9000;
             break;
           case 2:
/* 442 */             pt = 5750;
             break;
           case 3:
/* 445 */             pt = 3000;
             break;
         }
         break;
     }
/* 450 */     int exp = 0;
/* 451 */     if (rank < 4) {
/* 452 */       exp = (this.kill + this.cool * 5 + pt) * c.getClient().getChannelServer().getExpRate();
/* 453 */       c.gainExp(exp, true, false, false);
     }
/* 455 */     c.getTrait(MapleTraitType.will).addExp((this.type + 2) * 8, c);
/* 456 */     c.getClient().announce(MaplePacketCreator.showEffect("killing/clear"));
/* 457 */     c.getClient().announce(MaplePacketCreator.sendPyramidResult(rank, exp));
/* 458 */     dispose(c);
   }

   public final void fail(MapleCharacter c) {
     MapleMap map;
/* 463 */     if (this.type == -1) {
/* 464 */       map = c.getClient().getChannelServer().getMapFactory().getMap(910320001);
     } else {
/* 466 */       map = c.getClient().getChannelServer().getMapFactory().getMap(926010001 + this.type);
     }
/* 468 */     changeMap(c, map, 1, 200, 2);
/* 469 */     dispose(c);
   }

   public final void dispose(MapleCharacter c) {
/* 473 */     boolean lead = (this.energyBarDecrease != null && this.timerSchedule != null);
/* 474 */     if (this.energyBarDecrease != null) {
/* 475 */       this.energyBarDecrease.cancel(false);
/* 476 */       this.energyBarDecrease = null;
     }
/* 478 */     if (this.timerSchedule != null) {
/* 479 */       this.timerSchedule.cancel(false);
/* 480 */       this.timerSchedule = null;
     }
/* 482 */     if (c.getParty() != null && lead && c.getParty().getMembers().size() > 1) {
/* 483 */       fail(c);
       return;
     }
/* 486 */     c.setPyramidSubway(null);
   }

   public final void broadcastUpdate(MapleCharacter c) {
/* 490 */     c.getClient().announce(MaplePacketCreator.sendPyramidUpdate(this.bar));
   }

   public final void broadcastEffect(MapleCharacter c, String effect) {
/* 494 */     c.getClient().announce(MaplePacketCreator.showEffect(effect));
   }

   public final void broadcastEnergy(MapleCharacter c, String type, int amount) {
/* 498 */     c.getClient().announce(MaplePacketCreator.sendPyramidEnergy(type, String.valueOf(amount)));
   }
 }


/* Location:              C:\PGX\Server.jar!\server\maps\events\Event_PyramidSubway.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */